package com.lottery.entity;

import com.baomidou.mybatisplus.annotation.*;
import jakarta.validation.constraints.Min;
import java.time.LocalDateTime;

@TableName("user_chances")
public class UserChance {
    
    @TableId(type = IdType.AUTO)
    private Long id;
    
    @TableField("user_id")
    private Long userId;
    
    @Min(value = 0, message = "抽奖机会不能小于0")
    @TableField("chances")
    private Integer chances = 0;
    
    @TableField(value = "created_at", fill = FieldFill.INSERT)
    private LocalDateTime createdAt;
    
    @TableField(value = "updated_at", fill = FieldFill.INSERT_UPDATE)
    private LocalDateTime updatedAt;

    // 构造函数
    public UserChance() {}

    public UserChance(Long userId, Integer chances) {
        this.userId = userId;
        this.chances = chances;
    }
    
    // 业务方法
    public boolean hasChances() {
        return chances > 0;
    }
    
    public void useChance() {
        if (chances > 0) {
            chances--;
        }
    }
    
    public void addChances(Integer additionalChances) {
        if (additionalChances > 0) {
            this.chances += additionalChances;
        }
    }
    
    // Getters and Setters
    public Long getId() {
        return id;
    }
    
    public void setId(Long id) {
        this.id = id;
    }
    
    public Long getUserId() {
        return userId;
    }
    
    public void setUserId(Long userId) {
        this.userId = userId;
    }
    
    public Integer getChances() {
        return chances;
    }
    
    public void setChances(Integer chances) {
        this.chances = chances;
    }
    
    public LocalDateTime getCreatedAt() {
        return createdAt;
    }
    
    public void setCreatedAt(LocalDateTime createdAt) {
        this.createdAt = createdAt;
    }
    
    public LocalDateTime getUpdatedAt() {
        return updatedAt;
    }
    
    public void setUpdatedAt(LocalDateTime updatedAt) {
        this.updatedAt = updatedAt;
    }
}